<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');


/**
 * Parent Controller for all cms controllers.
 * @package core
 * @category CMS_Controller
 * 
 * @author Mark Angelo Angulo
 * @copyright (c) 2014
 */
class CMS_Controller extends CI_Controller {
    
    /**
     * Constructor method.
     */
    public function __construct() {
        parent::__construct();
        
        // Mixing segment-based URL with querystrings
        parse_str($_SERVER['QUERY_STRING'], $_GET);
        
        // Disable Notice and warnings
//        error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
        
        $this->load->config('cms-authentication/ion_auth');
        $this->load->model('cms-authentication/ion_auth_model');
        $this->load->library('cms-authentication/ion_auth'); 
        
        $cms = array();
        $cms['title'] = 'Bootstrap';
        $cms['db_prefix'] = 'bt_';
        $cms['limit'] = 1;
        $cms['theme'] = 'css';
        $cms['layout'] = 'boxed';
        $cms['navbar'] = 'static';
        $cms['footer'] = 'static';
        
        $this->cms = $cms;
        
//        $this->router->method
//        $this->_check_login();
    }
    
    /**
     * Validates if the current user is logged in.
     * @access private
     */
    private function _check_login()
    {
        if( ! $this->ion_auth->logged_in() )
        {
            header('location:' .  base_url());
        } else
        {
            // load necessary files
            $this->load->model('cms-users/group_role_model');
            $this->load->model('cms-modules/module_model');
            
            $this->load->helper('htmlpurifier');

            $this->load->library('form_validation');
            $this->form_validation->set_error_delimiters('<span class="help-block error" for="textfield">', '</span>');
            
            // retrieve user's username and ID
            $this->user_id = $this->ion_auth->user()->row()->id;
            $this->username = $this->ion_auth->user()->row()->username;

            // retrieve user's group ID
            $groups = $this->ion_auth->get_users_groups()->result_array();
            $this->group_id = $groups[0]['id'];
        }
    }
    
    /**
     * Displays the 404 page not found page.
     * @access protected
     */
    protected function show_404()
    {
        // clear any views that have already been loaded
        $this->output->set_output('');
        $this->output->set_status_header('404');
        $this->template
                ->set_layout('login')
                ->build('status_codes/404');
    }
    
    protected function show_403()
    {
        $this->output->set_output('');
        $this->output->set_status_header('403');
        $this->template
                ->set_layout('login')
                ->build('status_codes/403');
    }
}

/* End of file CMS_Controller.php */
/* Location: ./system/application/core/CMS_Controller.php */